import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TextFieldPage extends StatelessWidget {
  //定义一个controller
  TextEditingController _unameController = TextEditingController();
  TextEditingController _selectionController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    _selectionController.text = "hello world!";
    _selectionController.selection = TextSelection(
        baseOffset: 2, extentOffset: _selectionController.text.length);
    return Scaffold(
        appBar: AppBar(
          title: Text("TextField"),
        ),
        body:
            // Theme(
            //   data: Theme.of(context).copyWith(
            //     hintColor: Colors.grey[200],
            //     inputDecorationTheme: InputDecorationTheme(
            //         labelStyle: TextStyle(color: Colors.grey),
            //         hintStyle: TextStyle(color: Colors.grey, fontSize: 14)),
            //   ),
            //   child:
            Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            TextField(
                autofocus: true,
                decoration: InputDecoration(
                    labelText: "用户名",
                    hintText: "用户名或邮箱",
                    prefixIcon: Icon(Icons.person)),
                controller: _selectionController, //设置controller
                onChanged: (v) {
                  print("onChange: $v");
                }),
            TextField(
                autofocus: true,
                decoration: InputDecoration(
                    labelText: "用户名",
                    hintText: "用户名或邮箱",
                    prefixIcon: Icon(Icons.person)),
                controller: _unameController, //设置controller
                onChanged: (v) {
                  print("onChange: $v");
                }),
            TextField(
              decoration: InputDecoration(
                  labelText: "密码",
                  hintText: "您的登录密码",
                  prefixIcon: Icon(Icons.lock)),
              obscureText: true,
            ),
            TextField(
              decoration: InputDecoration(
                  labelText: "请输入用户名",
                  prefixIcon: Icon(Icons.person),
                  enabledBorder: UnderlineInputBorder(
                    borderSide: BorderSide(color: Colors.blue),
                  )),
            ),
            Container(
              child: TextField(
                  keyboardType: TextInputType.emailAddress,
                  decoration: InputDecoration(
                      labelText: "Email",
                      hintText: "电子邮件地址",
                      prefixIcon: Icon(Icons.email),
                      border: InputBorder.none //隐藏下划线
                      )),
              decoration: BoxDecoration(
                  // 下滑线浅灰色，宽度1像素
                  border: Border(
                      bottom:
                          BorderSide(color: Colors.grey[200]!, width: 1.0))),
            )
          ],
          // ),
        ));
  }
}
